package net.zjitc.controller;

import net.zjitc.domain.Admin;
import net.zjitc.service.Impl.ServiceImpl;
import net.zjitc.service.Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Administrator on 2017/11/22.
 */
@WebServlet(name = "LoginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        Service service=new ServiceImpl();
        Admin admin= service.fingUsernameAndPassword(username,password);
        if(admin.getUsername().equals(username)&&admin.getPassword().equals(password))
        {
            HttpSession session=request.getSession();
            session.setAttribute("admin",admin);
            response.sendRedirect("/shop/admin/home.jsp");
        }
        else {
            request.setAttribute("msg","??????????????");
            request.getRequestDispatcher("admin/login.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
